home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_lrm / chap11.doc < prev    next >
Text File  |  1996-01-30  |  35KB  |  816 lines

  1.                               11. Exceptions
  2.  
  3.  
  4. This  chapter  defines  the  facilities  for  dealing  with errors or other
  5. exceptional  situations  that  arise  during  program  execution.   Such  a
  6. situation  is  called  an  exception.   To raise an exception is to abandon
  7. normal program execution so as to draw  attention  to  the  fact  that  the
  8. corresponding situation has arisen.  Executing some actions, in response to
  9. the arising of an exception, is called handling the exception.
  10.  
  11.  
  12. An  exception  declaration  declares a name for an exception.  An exception
  13. can be raised by a  raise  statement,  or  it  can  be  raised  by  another
  14. statement  or  operation  that propagates the exception.  When an exception
  15. arises, control can be transferred to a user-provided exception handler  at
  16. the  end  of  a  block statement or at the end of the body of a subprogram,
  17. package, or task unit.
  18.  
  19.  
  20. References:  block statement 5.6, error situation  1.6,  exception  handler
  21. 11.2,  name  4.1,  package  body  7.1,  propagation  of an exception 11.4.1
  22. 11.4.2, raise statement 11.3, subprogram body 6.3, task body 9.1
  23.  
  24. 11.1  Exception Declarations
  25.  
  26.  
  27. An exception declaration declares a name for an exception.  The name of  an
  28. exception  can  only  be  used in raise statements, exception handlers, and
  29. renaming declarations.
  30.  
  31.  
  32.     exception_declaration ::= identifier_list : exception;
  33.  
  34.  
  35. An exception declaration  with  several  identifiers  is  equivalent  to  a
  36. sequence  of  single  exception  declarations, as explained in section 3.2.
  37. Each  single  exception  declaration  declares  a  name  for  a   different
  38. exception.   In  particular,  if  a  generic  unit  includes  an  exception
  39. declaration, the exception declarations implicitly generated  by  different
  40. instantiations  of  the  generic unit refer to distinct exceptions (but all
  41. have  the  same  identifier).   The  particular  exception  denoted  by  an
  42. exception name is determined at compilation time and is the same regardless
  43. of  how  many  times the exception declaration is elaborated.  Hence, if an
  44. exception declaration occurs in a recursive subprogram, the exception  name
  45. denotes the same exception for all invocations of the recursive subprogram.
  46.  
  47.  
  48. The  following  exceptions are predefined in the language;  they are raised
  49. when the situations described are detected.
  50.  
  51.  
  52. CONSTRAINT_ERROR  This  exception  is  raised  in  any  of  the   following
  53.                   situations:    upon   an   attempt  to  violate  a  range
  54.                   constraint,  an  index  constraint,  or  a   discriminant
  55.                   constraint;   upon  an  attempt to use a record component
  56.                   that does not exist for the current discriminant  values;
  57.                   and  upon  an  attempt  to  use  a selected component, an
  58.                   indexed component, a slice, or an attribute, of an object
  59.                   designated by an access value, if  the  object  does  not
  60.                   exist because the access value is null.
  61.  
  62.  
  63.    NUMERIC_ERROR  This exception is raised by the execution of a predefined
  64.                   numeric  operation  that  cannot deliver a correct result
  65.                   (within the declared  accuracy  for  real  types);   this
  66.                   includes   the   case  where  an  implementation  uses  a
  67.                   predefined   numeric   operation   for   the   execution,
  68.                   evaluation,  or elaboration of some construct.  The rules
  69.                   given in section 4.5.7  define  the  cases  in  which  an
  70.                   implementation  is  not  required to raise this exception
  71.                   when such an error situation arises;   see  also  section
  72.                   11.6.
  73.  
  74.  
  75.    PROGRAM_ERROR  This exception is  raised  upon  an  attempt  to  call  a
  76.                   subprogram, to activate a task, or to elaborate a generic
  77.                   instantiation,  if the body of the corresponding unit has
  78.                   not yet been elaborated.  This exception is  also  raised
  79.                   if the end of a function is reached (see 6.5);  or during
  80.                   the  execution of a selective wait that has no else part,
  81.                   if this execution determines that  all  alternatives  are
  82.                   closed   (see   9.7.1).    Finally,   depending   on  the
  83.                   implementation, this exception  may  be  raised  upon  an
  84.                   attempt  to  execute an action that is erroneous, and for
  85.                   incorrect order dependences (see 1.6).
  86.  
  87.  
  88.    STORAGE_ERROR  This  exception  is  raised  in  any  of  the   following
  89.                   situations:  when the dynamic storage allocated to a task
  90.                   is  exceeded;   during the evaluation of an allocator, if
  91.                   the space  available  for  the  collection  of  allocated
  92.                   objects  is  exhausted;   or  during the elaboration of a
  93.                   declarative item, or during the execution of a subprogram
  94.                   call, if storage is not sufficient.
  95.  
  96.  
  97.    TASKING_ERROR  This exception is raised  when  exceptions  arise  during
  98.                   intertask communication (see 9 and 11.5).
  99.  
  100. Note:
  101.  
  102.  
  103. The  situations described above can arise without raising the corresponding
  104. exceptions, if the pragma SUPPRESS has been used to give permission to omit
  105. the corresponding checks (see 11.7).
  106.  
  107.  
  108. Examples of user-defined exception declarations:
  109.  
  110.     SINGULAR : exception;
  111.     ERROR    : exception;
  112.     OVERFLOW, UNDERFLOW : exception;
  113.  
  114.  
  115. References:  access value 3.8, collection 3.8, declaration  3.1,  exception
  116. 11,  exception handler 11.2, generic body 12.2, generic instantiation 12.3,
  117. generic unit 12, identifier 2.3, implicit declaration  12.3,  instantiation
  118. 12.3,  name  4.1, object 3.2, raise statement 11.3, real type 3.5.6, record
  119. component 3.7, return statement 5.8, subprogram  6,  subprogram  body  6.3,
  120. task 9, task body 9.1
  121.  
  122.  
  123. Constraint_error exception contexts:  aggregate 4.3.1 4.3.2, allocator 4.8,
  124. assignment  statement  5.2 5.2.1, constraint 3.3.2, discrete type attribute
  125. 3.5.5, discriminant constraint  3.7.2,  elaboration  of  a  generic  formal
  126. parameter  12.3.1  12.3.2  12.3.4  12.3.5,  entry index 9.5, exponentiating
  127. operator 4.5.6, index constraint 3.6.1, indexed  component  4.1.1,  logical
  128. operator  4.5.1, null access value 3.8, object declaration 3.2.1, parameter
  129. association 6.4.1, qualified expression 4.7, range constraint 3.5, selected
  130. component 4.1.3, slice 4.1.2, subtype indication 3.3.2, type conversion 4.6
  131.  
  132.  
  133. Numeric_error exception contexts:  discrete type attribute 3.5.5,  implicit
  134. conversion  3.5.4 3.5.6 4.6, numeric operation 3.5.5 3.5.8 3.5.10, operator
  135. of a numeric type 4.5 4.5.7
  136.  
  137.  
  138. Program_error  exception  contexts:   collection  3.8,   elaboration   3.9,
  139. elaboration  check  3.9  7.3  9.3  12.2,  erroneous  1.6,  incorrect  order
  140. dependence 1.6, leaving a function 6.5, selective wait 9.7.1
  141.  
  142.  
  143. Storage_error exception contexts:  allocator 4.8
  144.  
  145.  
  146. Tasking error exception contexts:  abort statement  9.10,  entry  call  9.5
  147. 9.7.2 9.7.3, exceptions during task communication 11.5, task activation 9.3
  148.  
  149. 11.2  Exception Handlers
  150.  
  151.  
  152. The  response  to  one  or  more  exceptions  is  specified by an exception
  153. handler.
  154.  
  155.  
  156.     exception_handler ::=
  157.        when exception_choice {| exception_choice} =>
  158.           sequence_of_statements
  159.  
  160.     exception_choice ::= exception_name | others
  161.  
  162.  
  163. An exception handler occurs in a construct that is either a block statement
  164. or the body of a subprogram, package, task unit, or generic unit.   Such  a
  165. construct  will be called a frame in this chapter.  In each case the syntax
  166. of a frame that has exception handlers includes the following part:
  167.  
  168.  
  169.     begin
  170.         sequence_of_statements
  171.     exception
  172.         exception_handler
  173.        {exception_handler}
  174.     end
  175.  
  176.  
  177. The exceptions denoted by the exception names given as exception choices of
  178. a frame must all be distinct.  The exception choice others is only  allowed
  179. for the last exception handler of a frame and as its only exception choice;
  180. it  stands for all exceptions not listed in previous handlers of the frame,
  181. including exceptions whose names are  not  visible  at  the  place  of  the
  182. exception handler.
  183.  
  184.  
  185. The  exception handlers of a frame handle exceptions that are raised by the
  186. execution of the sequence of  statements  of  the  frame.   The  exceptions
  187. handled  by  a given exception handler are those named by the corresponding
  188. exception choices.
  189.  
  190.  
  191. Example:
  192.  
  193.     begin
  194.        --  sequence of statements
  195.     exception
  196.        when SINGULAR | NUMERIC_ERROR =>
  197.           PUT(" MATRIX IS SINGULAR ");
  198.        when others =>
  199.           PUT(" FATAL ERROR ");
  200.           raise ERROR;
  201.     end;
  202.  
  203. Note:
  204.  
  205.  
  206. The same kinds of statement are allowed in the sequence  of  statements  of
  207. each  exception handler as are allowed in the sequence of statements of the
  208. frame.   For example, a return statement is allowed in a handler  within  a
  209. function body.
  210.  
  211.  
  212. References:   block  statement  5.6,  declarative  part  3.9, exception 11,
  213. exception handling 11.4, function body 6.3, generic body 12.2, generic unit
  214. 12.1, name 4.1, package body 7.1, raise statement  11.3,  return  statement
  215. 5.8,  sequence  of  statements  5.1, statement 5, subprogram body 6.3, task
  216. body 9.1, task unit 9 9.1, visibility 8.3
  217.  
  218. 11.3  Raise Statements
  219.  
  220.  
  221. A raise statement raises an exception.                        
  222.  
  223.  
  224.     raise_statement ::= raise [exception_name];
  225.  
  226.  
  227. For the execution of a raise statement with an exception  name,  the  named
  228. exception  is  raised.  A raise statement without an exception name is only
  229. allowed within an  exception  handler  (but  not  within  the  sequence  of
  230. statements  of  a subprogram, package, task unit, or generic unit, enclosed
  231. by the handler);  it raises again the exception that caused transfer to the
  232. innermost enclosing handler.
  233.  
  234.  
  235. Examples:
  236.  
  237.     raise SINGULAR;
  238.     raise NUMERIC_ERROR;  --  explicitly raising a predefined exception
  239.  
  240.     raise;                --  only within an exception handler
  241.  
  242.  
  243. References:  exception 11, generic unit 12, name 4.1, package  7,  sequence
  244. of statements 5.1, subprogram 6, task unit 9
  245.  
  246. 11.4  Exception Handling
  247.  
  248.  
  249. When  an  exception  is  raised,  normal program execution is abandoned and
  250. control is transferred to an exception  handler.   The  selection  of  this
  251. handler  depends on whether the exception is raised during the execution of
  252. statements or during the elaboration of declarations.
  253.  
  254.  
  255. References:  declaration 3.1, elaboration 3.1 3.9, exception 11,  exception
  256. handler 11.2, raising of exceptions 11.3, statement 5
  257.  
  258. 11.4.1  Exceptions Raised During the Execution of Statements
  259.  
  260.  
  261. The  handling  of  an  exception  raised  by the execution of a sequence of
  262. statements depends on whether the innermost frame or accept statement  that
  263. encloses the sequence of statements is a frame or an accept statement.  The
  264. case  where  an accept statement is innermost is described in section 11.5.
  265. The case where a frame is innermost is presented here.
  266.  
  267.  
  268. Different actions take place, depending on whether or not this frame has  a
  269. handler  for  the  exception, and on whether the exception is raised in the
  270. sequence of statements of the frame or in that of an exception handler.
  271.  
  272.  
  273. If an exception is raised in the sequence of statements of a frame that has
  274. a handler for the exception, execution of the sequence of statements of the
  275. frame is abandoned and control is transferred  to  the  exception  handler.
  276. The  execution  of  the sequence of statements of the handler completes the
  277. execution of the frame (or its elaboration if the frame is a package body).
  278.  
  279.  
  280. If an exception is raised in the sequence of statements  of  a  frame  that
  281. does  not  have  a handler for the exception, execution of this sequence of
  282. statements is abandoned.  The next action depends  on  the  nature  of  the
  283. frame:
  284.  
  285.  
  286. (a)  For a subprogram body, the same exception is raised again at the point
  287.      of  call  of the subprogram, unless the subprogram is the main program
  288.      itself, in which case execution of the main program is abandoned.
  289.  
  290.  
  291. (b)  For a block statement, the same exception is raised again  immediately
  292.      after  the  block  statement  (that is, within the innermost enclosing
  293.      frame or accept statement).
  294.  
  295.  
  296. (c)  For a package body that is a declarative item, the same  exception  is
  297.      raised  again  immediately  after  this  declarative  item (within the
  298.      enclosing declarative part). If the package body is that of a subunit,
  299.      the exception is raised again at the place of the  corresponding  body
  300.      stub.  If the package is a library unit, execution of the main program
  301.      is abandoned.
  302.  
  303.  
  304. (d)  For a task body, the task becomes completed.
  305.  
  306.  
  307. An exception that is raised again (as in the above cases (a), (b), and (c))
  308. is  said  to  be propagated, either by the execution of the subprogram, the
  309. execution of the block statement, or the elaboration of the  package  body.
  310. No  propagation  takes place in the case of a task body.  If the frame is a
  311. subprogram or a  block  statement  and  if  it  has  dependent  tasks,  the
  312. propagation  of  an  exception  takes  place  only after termination of the
  313. dependent tasks.
  314.  
  315.  
  316. Finally, if an exception is raised in the  sequence  of  statements  of  an
  317. exception  handler,  execution of this sequence of statements is abandoned.
  318. Subsequent actions (including propagation, if any) are as in the cases  (a)
  319. to (d) above, depending on the nature of the frame.
  320.  
  321.  
  322. Example:
  323.  
  324.     function FACTORIAL (N : POSITIVE) return FLOAT is
  325.     begin
  326.        if N = 1 then
  327.           return 1.0;
  328.        else
  329.           return FLOAT(N) * FACTORIAL(N-1);
  330.        end if;
  331.     exception
  332.        when NUMERIC_ERROR => return FLOAT'SAFE_LARGE;
  333.     end FACTORIAL;
  334.  
  335.  
  336. If  the  multiplication  raises  NUMERIC_ERROR,  then  FLOAT'SAFE_LARGE  is
  337. returned by the handler.   This  value  will  cause  further  NUMERIC_ERROR
  338. exceptions  to be raised by the evaluation of the expression in each of the
  339. remaining invocations of the function, so that for large values  of  N  the
  340. function will ultimately return the value FLOAT'SAFE_LARGE.
  341.  
  342.  
  343. Example:
  344.  
  345.     procedure P is
  346.        ERROR : exception;
  347.        procedure R;
  348.  
  349.        procedure Q is
  350.        begin
  351.           R;
  352.           ...            --  error situation (2)
  353.        exception
  354.           ...
  355.           when ERROR =>  --  handler E2
  356.           ...
  357.        end Q;
  358.  
  359.        procedure R is
  360.        begin
  361.           ...            --  error situation (3)
  362.        end R;
  363.  
  364.     begin
  365.        ...               --  error situation (1)
  366.        Q;
  367.        ...
  368.     exception
  369.        ...
  370.        when ERROR =>     --  handler E1
  371.        ...
  372.     end P;
  373.  
  374.  
  375. The following situations can arise:
  376.  
  377.  
  378. (1)  If the exception ERROR is raised in the sequence of statements of  the
  379.      outer  procedure  P,  the  handler  E1  provided  within  P is used to
  380.      complete the execution of P.
  381.  
  382.  
  383. (2)  If the exception ERROR is raised in the sequence of statements  of  Q,
  384.      the  handler E2 provided within Q is used to complete the execution of
  385.      Q.  Control will be returned to the point of call of Q upon completion
  386.      of the handler.
  387.  
  388.  
  389. (3)  If the exception ERROR is raised in the body of R, called  by  Q,  the
  390.      execution  of  R  is abandoned and the same exception is raised in the
  391.      body of Q.  The handler E2 is then used to complete the  execution  of
  392.      Q, as in situation (2).
  393.  
  394.  
  395. Note  that  in  the  third  situation, the exception raised in R results in
  396. (indirectly) transferring control to a handler that is part of Q and  hence
  397. not  enclosed by R.  Note also that if a handler were provided within R for
  398. the exception choice others, situation (3) would cause  execution  of  this
  399. handler, rather than direct termination of R.
  400.  
  401.  
  402. Lastly,  if ERROR had been declared in R, rather than in P, the handlers E1
  403. and E2  could  not  provide  an  explicit  handler  for  ERROR  since  this
  404. identifier would not be visible within the bodies of P and Q.  In situation
  405. (3), the exception could however be handled in Q by providing a handler for
  406. the exception choice others.
  407.  
  408. Notes:
  409.  
  410.  
  411. The  language  does  not define what happens when the execution of the main
  412. program is abandoned after an unhandled exception.
  413.  
  414.  
  415. The predefined exceptions are those that can be  propagated  by  the  basic
  416. operations and the predefined operators.
  417.  
  418.  
  419. The  case of a frame that is a generic unit is already covered by the rules
  420. for subprogram and package bodies, since the sequence of statements of such
  421. a frame is not executed but is the template for the corresponding sequences
  422. of  statements  of  the  subprograms  or  packages  obtained   by   generic
  423. instantiation.
  424.  
  425.  
  426. References:   accept  statement 9.5, basic operation 3.3.3, block statement
  427. 5.6, body stub 10.2, completion 9.4, declarative item 3.9, declarative part
  428. 3.9, dependent task 9.4,  elaboration  3.1  3.9,  exception  11,  exception
  429. handler  11.2,  frame  11.2,  generic  instantiation 12.3, generic unit 12,
  430. library unit 10.1, main program 10.1, numeric_error exception 11.1, package
  431. 7, package body 7.1, predefined operator 4.5, procedure  6.1,  sequence  of
  432. statements  5.1, statement 5, subprogram 6, subprogram body 6.3, subprogram
  433. call 6.4, subunit 10.2, task 9, task body 9.1
  434.  
  435. 11.4.2  Exceptions Raised During the Elaboration of Declarations
  436.  
  437.  
  438. If an exception is raised during the elaboration of the declarative part of
  439. a given frame, this elaboration is abandoned.  The next action  depends  on
  440. the nature of the frame:
  441.  
  442.  
  443. (a)  For a subprogram body, the same exception is raised again at the point
  444.      of  call  of the subprogram, unless the subprogram is the main program
  445.      itself, in which case execution of the main program is abandoned.
  446.  
  447.  
  448. (b)  For a block statement, the same exception is raised again  immediately
  449.      after the block statement.
  450.  
  451.  
  452. (c)  For a package body that is a declarative item, the same  exception  is
  453.      raised again immediately after this declarative item, in the enclosing
  454.      declarative  part.   If  the  package  body  is that of a subunit, the
  455.      exception is raised again at the place of the corresponding body stub.
  456.      If the package is a library unit, execution of  the  main  program  is
  457.      abandoned.
  458.  
  459.  
  460. (d)  For a task  body,  the  task  becomes  completed,  and  the  exception
  461.      TASKING_ERROR  is  raised  at  the point of activation of the task, as
  462.      explained in section 9.3.
  463.  
  464.  
  465. Similarly, if an exception is raised during the  elaboration  of  either  a
  466. package  declaration  or a task declaration, this elaboration is abandoned;
  467. the next action depends on the nature of the declaration.
  468.  
  469.  
  470. (e)  For a package declaration or a task declaration, that is a declarative
  471.      item, the exception is raised again immediately after the  declarative
  472.      item  in the enclosing declarative part or package specification.  For
  473.      the declaration of a  library  package,  the  execution  of  the  main
  474.      program is abandoned.
  475.  
  476.  
  477. An  exception that is raised again (as in the above cases (a), (b), (c) and
  478. (e)) is said to be propagated, either by the execution of the subprogram or
  479. block statement, or by the elaboration of  the  package  declaration,  task
  480. declaration or package body.
  481.  
  482.  
  483. Example  of an exception in the declarative part of a block statement (case
  484. (b)):
  485.  
  486.     procedure P is
  487.        ...
  488.     begin
  489.        declare
  490.           N : INTEGER := F;  --  the function F may raise ERROR
  491.        begin
  492.           ...
  493.        exception
  494.           when ERROR =>      --  handler E1
  495.        end;
  496.        ...
  497.     exception
  498.        when ERROR =>         --  handler E2
  499.     end P;
  500.  
  501.     --  if the exception ERROR is raised in the declaration of N, it is handled by E2
  502.  
  503.  
  504. References:  activation 9.3, block statement 5.6, body stub 10.2, completed
  505. task 9.4, declarative item 3.9, declarative part 3.9, elaboration 3.1  3.9,
  506. exception  11,  frame  11.2,  library unit 10.1, main program 10.1, package
  507. body 7.1, package declaration 7.1, package specification 7.1, subprogram 6,
  508. subprogram body 6.3, subprogram call 6.4, subunit 10.2, task 9,  task  body
  509. 9.1, task declaration 9.1, tasking_error exception 11.1
  510.  
  511. 11.5  Exceptions Raised During Task Communication
  512.  
  513.  
  514. An  exception  can  be propagated to a task communicating, or attempting to
  515. communicate, with another task.  An exception can also be propagated  to  a
  516. calling task if the exception is raised during a rendezvous.
  517.  
  518.  
  519. When  a task calls an entry of another task, the exception TASKING_ERROR is
  520. raised in the calling task, at the place of the call, if the called task is
  521. completed before accepting the entry call or is already  completed  at  the
  522. time of the call.
  523.  
  524.  
  525. A rendezvous can be completed abnormally in two cases:
  526.  
  527.  
  528. (a)  When an exception is  raised  within  an  accept  statement,  but  not
  529.      handled  within  an  inner  frame.  In this case, the execution of the
  530.      accept statement is abandoned and the same exception is  raised  again
  531.      immediately  after  the  accept  statement within the called task; the
  532.      exception is also propagated to the calling task at the point  of  the
  533.      entry call.
  534.  
  535.  
  536. (b)  When the task containing the accept statement is completed  abnormally
  537.      as  the  result  of  an  abort statement.  In this case, the exception
  538.      TASKING_ERROR is raised in the calling task at the point of the  entry
  539.      call.                                                                 
  540.  
  541.  
  542. On the other hand, if a task issuing an entry call becomes abnormal (as the
  543. result  of  an  abort statement) no exception is raised in the called task.
  544. If the rendezvous has not yet started, the entry call is cancelled.  If the
  545. rendezvous is in progress, it completes normally, and the  called  task  is
  546. unaffected.
  547.  
  548.  
  549. References:   abnormal  task  9.10,  abort statement 9.10, accept statement
  550. 9.5, completed  task  9.4,  entry  call  9.5,  exception  11,  frame  11.2,
  551. rendezvous  9.5, task 9, task termination 9.4, tasking_error exception 11.1
  552.  
  553. 11.6  Exceptions and Optimization
  554.  
  555.  
  556. The purpose of this section is to specify the  conditions  under  which  an
  557. implementation  is  allowed  to  perform  certain actions either earlier or
  558. later than specified by other rules of the language.
  559.  
  560.  
  561. In general, when the language rules specify an order  for  certain  actions
  562. (the  canonical order), an implementation may only use an alternative order
  563. if it can guarantee that the effect of the program is not  changed  by  the
  564. reordering.   In particular, no exception should arise for the execution of
  565. the reordered program if none arises for the execution of  the  program  in
  566. the canonical order.  When, on the other hand, the order of certain actions
  567. is   not   defined   by  the  language,  any  order  can  be  used  by  the
  568. implementation.  (For example, the arguments of a predefined  operator  can
  569. be  evaluated  in  any   order  since the rules given in section 4.5 do not
  570. require a specific order of evaluation.)
  571.  
  572.  
  573. Additional freedom is left to  an  implementation  for  reordering  actions
  574. involving  predefined  operations  that  are either predefined operators or
  575. basic operations other than assignments.  This freedom is left, as  defined
  576. below,  even in the case where the execution of these predefined operations
  577. may propagate a (predefined) exception:
  578.  
  579.  
  580. (a)  For the purpose of establishing whether the same effect is obtained by
  581.      the  execution  of  certain  actions  in  the  canonical  and  in   an
  582.      alternative  order,  it  can  be  assumed  that none of the predefined
  583.      operations  invoked  by  these  actions  propagates   a   (predefined)
  584.      exception, provided that the two following requirements are met by the
  585.      alternative  order:   first,  an  operation must not be invoked in the
  586.      alternative order if  it  is  not  invoked  in  the  canonical  order;
  587.      second,  for  each  operation, the innermost enclosing frame or accept
  588.      statement must be  the  same  in  the  alternative  order  as  in  the
  589.      canonical order, and the same exception handlers must apply.
  590.  
  591.  
  592. (b)  Within an expression, the association of operators  with  operands  is
  593.      specified  by  the  syntax.   However,  for  a  sequence of predefined
  594.      operators of  the  same  precedence  level  (and  in  the  absence  of
  595.      parentheses  imposing  a  specific  association),  any  association of
  596.      operators with operands is  allowed  if  it  satisfies  the  following
  597.      requirement:   an  integer  result  must be equal to that given by the
  598.      canonical left-to-right order;  a  real  result  must  belong  to  the
  599.      result  model  interval  defined for the canonical left-to-right order
  600.      (see 4.5.7).  Such a reordering is allowed even if it  may  remove  an
  601.      exception, or introduce a further predefined exception.
  602.  
  603.  
  604. Similarly,  additional  freedom  is  left  to  an  implementation  for  the
  605. evaluation  of  numeric  simple  expressions.   For  the  evaluation  of  a
  606. predefined  operation, an implementation is allowed to use the operation of
  607. a type that has a range wider than that of the base type of  the  operands,
  608. provided  that  this  delivers  the  exact  result  (or a result within the
  609. declared accuracy, in the case of a real type), even if  some  intermediate
  610. results   lie   outside   the  range  of  the  base  type.   The  exception
  611. NUMERIC_ERROR need not be raised in such a case.   In  particular,  if  the
  612. numeric  expression  is an operand of a predefined relational operator, the
  613. exception NUMERIC_ERROR need  not  be  raised  by  the  evaluation  of  the
  614. relation, provided that the correct BOOLEAN result is obtained.
  615.  
  616.  
  617. A  predefined  operation  need  not be invoked at all, if its only possible
  618. effect is to propagate a predefined  exception.   Similarly,  a  predefined
  619. operation  need  not  be invoked if the removal of subsequent operations by
  620. the above rule renders this invocation ineffective.
  621.  
  622. Notes:
  623.  
  624.  
  625. Rule (b) applies to predefined  operators  but  not  to  the  short-circuit
  626. control forms.
  627.  
  628.  
  629. The  expression  SPEED  <  300_000.0  can  be replaced by TRUE if the value
  630. 300_000.0 lies outside the base type of SPEED,  even  though  the  implicit
  631. conversion  of the numeric literal would raise the exception NUMERIC_ERROR.
  632.  
  633.  
  634. Example:
  635.  
  636.     declare
  637.        N : INTEGER;
  638.     begin
  639.        N := 0;               --  (1)
  640.        for J in 1 .. 10 loop
  641.           N := N + J**A(K);  --  A and K are global variables
  642.        end loop;
  643.        PUT(N);
  644.     exception
  645.        when others => PUT("Some error arose"); PUT(N);
  646.     end;
  647.  
  648.  
  649. The evaluation of A(K) may be  performed  before  the  loop,  and  possibly
  650. immediately before the assignment statement (1) even if this evaluation can
  651. raise  an exception.  Consequently, within the exception handler, the value
  652. of N is either the undefined initial value or a value later  assigned.   On
  653. the  other  hand, the evaluation of A(K) cannot be moved before begin since
  654. an exception would then be  handled  by  a  different  handler.   For  this
  655. reason, the initialization of N in the declaration itself would exclude the
  656. possibility of having an undefined initial value of N in the handler.
  657.  
  658.  
  659. References:   accept  statement  9.5,  accuracy  of  real operations 4.5.7,
  660. assignment 5.2, base type 3.3, basic operation 3.3.3, conversion 4.6, error
  661. situation  11,  exception  11,  exception   handler   11.2,   frame   11.2,
  662. numeric_error   exception   11.1,   predefined   operator  4.5,  predefined
  663. subprogram  8.6,  propagation  of  an  exception  11.4,  real  type  3.5.6,
  664. undefined value 3.2.1
  665.  
  666. 11.7  Suppressing Checks
  667.  
  668.  
  669. The  presence of a SUPPRESS pragma gives permission to an implementation to
  670. omit certain run-time checks.  The form of this pragma is as follows:
  671.  
  672.     pragma SUPPRESS(identifier [, [ON =>] name]);
  673.  
  674.  
  675. The identifier is that of the check that can  be  omitted.   The  name  (if
  676. present)  must  be  either  a  simple  name or an expanded name and it must
  677. denote either an object, a type or subtype, a task unit, or a generic unit;
  678. alternatively the name can be a subprogram name, in which case it can stand
  679. for several visible overloaded subprograms.
  680.  
  681.  
  682. A pragma SUPPRESS is only allowed immediately within a declarative part  or
  683. immediately  within  a package specification.  In the latter case, the only
  684. allowed form is with a name that denotes an entity (or  several  overloaded
  685. subprograms)  declared  immediately  within the package specification.  The
  686. permission to omit the given check extends from the place of the pragma  to
  687. the  end  of the declarative region associated with the innermost enclosing
  688. block statement  or  program  unit.   For  a  pragma  given  in  a  package
  689. specification,  the permission extends to the end of the scope of the named
  690. entity.
  691.  
  692.  
  693. If the pragma includes a name, the permission to omit the  given  check  is
  694. further restricted:  it is given only for operations on the named object or
  695. on all objects of the base type of a named type or subtype;  for calls of a
  696. named subprogram;  for activations of tasks of the named task type;  or for
  697. instantiations of the given generic unit.
  698.  
  699.  
  700. The  following  checks  correspond  to  situations  in  which the exception
  701. CONSTRAINT_ERROR may be raised; for these checks,  the  name  (if  present)
  702. must denote either an object or a type.
  703.  
  704.  
  705. ACCESS_CHECK          When  accessing  a  selected  component,  an  indexed
  706.                       component,  a  slice,  or  an attribute, of an object
  707.                       designated by an access value, check that the  access
  708.                       value is not null.
  709.  
  710.  
  711. DISCRIMINANT_CHECK    Check that a discriminant of a  composite  value  has
  712.                       the  value  imposed  by  a  discriminant  constraint.
  713.                       Also, when accessing a record component,  check  that
  714.                       it exists for the current discriminant values.
  715.  
  716.  
  717. INDEX_CHECK           Check that the bounds of an array value are equal  to
  718.                       the  corresponding  bounds  of  an  index constraint.
  719.                       Also, when accessing a component of an array  object,
  720.                       check  for  each dimension that the given index value
  721.                       belongs to the range defined by  the  bounds  of  the
  722.                       array  object.   Also,  when  accessing a slice of an
  723.                       array object, check that the given discrete range  is
  724.                       compatible  with  the  range defined by the bounds of
  725.                       the array object.
  726.  
  727.  
  728. LENGTH_CHECK          Check that there is a  matching  component  for  each
  729.                       component   of   an  array,  in  the  case  of  array
  730.                       assignments, type conversions, and logical  operators
  731.                       for arrays of boolean components.
  732.  
  733.  
  734. RANGE_CHECK           Check that a  value  satisfies  a  range  constraint.
  735.                       Also,  for  the  elaboration of a subtype indication,
  736.                       check that the constraint (if present) is  compatible
  737.                       with  the  type  mark.  Also, for an aggregate, check
  738.                       that an index or discriminant value  belongs  to  the
  739.                       corresponding   subtype.    Finally,  check  for  any
  740.                       constraint   checks   performed    by    a    generic
  741.                       instantiation.
  742.  
  743.  
  744. The  following  checks  correspond  to  situations  in  which the exception
  745. NUMERIC_ERROR is raised.  The  only  allowed  names  in  the  corresponding
  746. pragmas are names of numeric types.
  747.  
  748.  
  749. DIVISION_CHECK        Check that the second operand is  not  zero  for  the
  750.                       operations /, rem and mod.
  751.  
  752.  
  753. OVERFLOW_CHECK        Check that the result of a numeric operation does not
  754.                       overflow.
  755.  
  756.  
  757. The  following  check  corresponds  to  situations  in  which the exception
  758. PROGRAM_ERROR is raised.  The  only  allowed  names  in  the  corresponding
  759. pragmas are names denoting task units, generic units, or subprograms.
  760.  
  761.  
  762. ELABORATION_CHECK     When either a subprogram is called, a task activation
  763.                       is   accomplished,  or  a  generic  instantiation  is
  764.                       elaborated, check that the body of the  corresponding
  765.                       unit has already been elaborated.
  766.  
  767.  
  768. The  following  check  corresponds  to  situations  in  which the exception
  769. STORAGE_ERROR is raised.  The  only  allowed  names  in  the  corresponding
  770. pragmas are names denoting access types, task units, or subprograms.
  771.  
  772.  
  773. STORAGE_CHECK         Check that execution of an allocator does not require
  774.                       more space than is available for a collection.  Check
  775.                       that the space available for a task or subprogram has
  776.                       not been exceeded.
  777.  
  778.  
  779. If  an  error situation arises in the absence of the corresponding run-time
  780. checks, the execution of the program is  erroneous  (the  results  are  not
  781. defined by the language).
  782.  
  783.  
  784. Examples:
  785.  
  786.     pragma SUPPRESS(RANGE_CHECK);
  787.     pragma SUPPRESS(INDEX_CHECK, ON => TABLE);
  788.  
  789. Notes:
  790.  
  791.  
  792. For certain implementations, it may be impossible or too costly to suppress
  793. certain  checks.  The corresponding SUPPRESS pragma can be ignored.  Hence,
  794. the occurrence of such a pragma within a given unit does not guarantee that
  795. the corresponding exception will not arise;  the  exceptions  may  also  be
  796. propagated by called units.
  797.  
  798.  
  799. References:
  800. access type 3.8, access value 3.8, activation 9.3, aggregate 4.3, allocator
  801. 4.8,  array  3.6,  attribute  4.1.4,  block  statement 5.6, collection 3.8,
  802. compatible 3.3.2, component of an array 3.6, component  of  a  record  3.7,
  803. composite  type  3.3,  constraint  3.3,  constraint_error  exception  11.1,
  804. declarative part 3.9, designate 3.8, dimension  3.6,  discrete  range  3.6,
  805. discriminant  3.7.1,  discriminant  constraint  3.7.2, elaboration 3.1 3.9,
  806. erroneous 1.6, error situation 11, expanded name 4.1.3, generic body  11.1,
  807. generic  instantiation  12.3,  generic  unit 12, identifier 2.3, index 3.6,
  808. index constraint 3.6.1, indexed component 4.1.1,  null  access  value  3.8,
  809. numeric  operation  3.5.5  3.5.8  3.5.10,  numeric  type 3.5, numeric_error
  810. exception 11.1, object 3.2, operation  3.3.3,  package  body  7.1,  package
  811. specification  7.1,  pragma 2.8, program_error exception 11.1, program unit
  812. 6, propagation of an exception 11.4, range constraint 3.5, record type 3.7,
  813. simple name 4.1, slice 4.1.2, subprogram 6, subprogram body 6.3, subprogram
  814. call 6.4, subtype 3.3, subunit 10.2, task 9, task body 9.1, task type  9.1,
  815. task unit 9, type 3.3, type mark 3.3.2
  816.